﻿using SXT.Party.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace ZHDJ.MobileInterface
{
    /// <summary>
    /// MobileInterfaceServiceEx 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class MobileInterfaceServiceWeb : System.Web.Services.WebService
    {

        [WebMethod]
        public string PushInformation(string id, string publishTime, string source, string title, string type)
        {
            string logMsg = "";
            string paramStr = "";
            string resultStr = "";
            PushInformationInParam inparam = new PushInformationInParam();
            try
            {
                //inparam.id = id;
                //inparam.publishTime = publishTime;
                //inparam.source = source;
                //inparam.title = title;
                //inparam.type = type;
                //inparam.url = ServiceSettings.AppAddress + "Ms/html/InformationDetail.aspx";
                //paramStr = string.Format("[{0}][{1}][{2}][{3}][{4}][{5}]", id, publishTime, source, title, type, inparam.url);

                //string mobielUrl = ServiceSettings.MobileInterfaceUrl + string.Format("thdj/pushnotification/pushnotificationAction!push.action?id={0}&publishTime={1}&source={2}&title={3}&type={4}&url={5}",
                //    inparam.id, inparam.publishTime, inparam.source, inparam.title, inparam.type, inparam.url);
                //PushInformationOutParam result = PushHelper.PushMessage<PushInformationInParam, PushInformationOutParam>(mobielUrl, inparam);

                //resultStr = SerializeHelper.JsonSerializer<PushInformationOutParam>(result);

                InterfaceHelper.SendInfoDaoyi(id, publishTime, source, title, type);
            }
            catch (Exception ex)
            {
                logMsg = ex.Message + ":" + ex.StackTrace;
                resultStr = ""; ;
            }
            //CommonUtils.InsertMobileInterfaceLog(SystemCode +"-PushInformation", paramStr, resultStr + ":" + logMsg);

            return resultStr;
        }

        /// <summary>
        /// 短信发送
        /// </summary>
        /// <param name="conten">短信内容，不能超过1024个字符</param>
        /// <param name="mobiles">手机号码，多个手机号码以小写逗号分隔</param>
        /// <param name="validate">验证码（由接口提供）</param>
        /// SystemCode  厂商编号
        /// CryptograhpyKey  厂商密码
        /// <returns></returns>
        [WebMethod(Description = "短信发送")]
        public string SMSSend(string conten, string mobiles, string SystemCode, string CryptograhpyKey)
        {
            string SCode = System.Configuration.ConfigurationManager.AppSettings["ServiceSettings.SystemCode"];
            string CKey = System.Configuration.ConfigurationManager.AppSettings["ServiceSettings.CryptograhpyKey"];
            int i = 0;
            bool IsTrue = false;
            foreach (string name in SCode.Split(';'))
            {
                if (name == SystemCode)
                {
                    IsTrue = true;
                    break;
                }
                i++;
            }
            List<string> lstMobile = new List<string>();
            string[] mobileArray = mobiles.Split(',');
            foreach (string item in mobileArray)
            { lstMobile.Add(item); }

            if (IsTrue)
            {
                if (CryptograhpyKey != CKey.Split(';')[i])
                {
                    ///写日志，密钥不对
                    PartyMOSms.InsertSmsSendLog(conten, lstMobile, "101", "密钥不正确" + SystemCode + "-" + CryptograhpyKey, "", SystemCode);
                    return "101";
                }
            }
            else {
                ///写日志，厂商编号不存在
                PartyMOSms.InsertSmsSendLog(conten, lstMobile, "100", "厂商编号不存在" + SystemCode + "-" + CryptograhpyKey, "", SystemCode);
                return "100";
            }

            return PartyMOSms.SmsSend(conten, lstMobile, "", SystemCode);
        }
    }
}
